<script setup lang="ts">
// #ifdef MP
import { onAddToFavorites, onShareAppMessage, onShareTimeline } from '@dcloudio/uni-app'
import { wxCollect, wxShare } from '@/libs/share'

onShareAppMessage(wxShare(true))
onShareTimeline(wxShare(false))
onAddToFavorites(wxCollect())
// #endif

import { onMounted, onUnmounted } from 'vue'

import { list, curIdx, isBottom, isUpdating } from './data'
import { update, viewReport, deleteReport, clear } from './data'
import { imagePath, maskStyle } from '@/libs/file-utils'

const icon_logo = imagePath('quiz/result/list/icon-logo.png')
const icon_delete = imagePath('icon-delete.svg')

onMounted(update)
onUnmounted(clear)
</script>

<template>
  <PageWrapper
    name="quiz-result-list"
    :pageStyle="{ backgroundColor: '#EBCFF2' }"
  >
    <scroll-view
      class="list"
      scroll-y
      :show-scrollbar="false"
      :lower-threshold="200"
      @scrolltolower="update"
    >
      <div
        v-for="(item, idx) in list"
        :key="idx"
        class="item"
        @click="curIdx = idx"
      >
        <div
          class="icon"
          :class="{ active: curIdx === idx }"
        >
          <div class="circle"></div>
          <div
            class="inner"
            :style="{ backgroundImage: icon_logo }"
          ></div>
        </div>

        <div class="name">{{ item.reportName }}</div>
        <div class="date">{{ item.createdTime }}&nbsp;&nbsp;{{ item.typeName }}</div>

        <div
          class="view"
          @click="item.testStatus === 2 && viewReport(item)"
        >{{ item.testStatus === 2 ? '查看' : '生成中' }}</div>
      </div>

      <div
        class="tip"
        @click="update"
      >{{ isBottom ? '—— 到底了 ——' : isUpdating ? '加载中' : '加载更多' }}</div>
    </scroll-view>

    <div
      class="delete"
      @click="deleteReport"
    >
      <div
        class="icon"
        :style="maskStyle(icon_delete)"
      ></div>
      删除
    </div>
  </PageWrapper>
</template>

<style lang="less" scoped>
.list {
  width: 100%;
  height: 100%;

  box-sizing: border-box;
  padding: 0 32rpx;

  touch-action: pan-y;

  .item {
    position: relative;
    width: 100%;
    height: 160rpx;

    margin-top: 32rpx;

    box-sizing: border-box;
    padding-left: 116rpx;
    padding-top: 36rpx;

    border-radius: 32rpx;
    background-color: #FFF6FF;
    box-shadow: 0 4rpx 8rpx 0 rgba(116, 61, 167, .46);

    .icon {
      position: absolute;
      top: 52rpx;
      left: 28rpx;

      width: 56rpx;
      height: 56rpx;

      .circle {
        position: absolute;
        top: 50%;
        left: 50%;

        width: 32rpx;
        height: 32rpx;

        box-sizing: border-box;
        border: 2rpx solid #8B41FF;
        border-radius: 50%;

        transform: translate(-50%, -50%)scale(1);
        transition: transform .3s;
      }

      .inner {
        position: absolute;
        top: 0;
        left: 0;

        width: 100%;
        height: 100%;

        transform: scale(0);
        transition: transform .3s;
      }

      &.active {
        .circle {
          transform: translate(-50%, -50%)scale(0);
        }

        .inner {
          transform: scale(1);
        }
      }
    }

    .name {
      color: #51158E;
      font-size: 40rpx;
      line-height: 48rpx;
    }

    .date {
      margin-top: 8rpx;

      color: #51158E;
      font-size: 24rpx;
      line-height: 32rpx;
    }
  }

  .view {
    position: absolute;
    top: 50%;
    right: 14rpx;
    transform: translateY(-50%);

    width: 146rpx;
    height: 70rpx;

    box-sizing: border-box;
    background-color: #9D57FF;
    box-shadow: inset 0 0 8rpx 0 rgba(233, 196, 255, .51), inset 0 2rpx 3rpx 0 rgba(#fff, .57), 0 2rpx 2rpx 0 rgba(84, 0, 136, .24);
    border-radius: 60rpx;
    border: 4rpx solid #b176ff;

    color: #fff;
    font-size: 32rpx;
    line-height: 70rpx;
    text-align: center;
  }

  .tip {
    height: 400rpx;

    color: #666;
    font-size: 28rpx;
    line-height: 160rpx;
    text-align: center;
  }
}

.delete {
  position: fixed;
  bottom: 100rpx;
  left: 50%;
  transform: translateX(-50%);

  width: 622rpx;
  height: 116rpx;

  background-color: #FFEBFF;
  box-shadow: inset 0rpx 4rpx 4rpx 0rpx #F8EAFF, inset 0rpx -4rpx 3rpx 0rpx rgba(118, 0, 179, .3), 0rpx 4rpx 20rpx 0rpx rgba(59, 3, 112, .13);
  border-radius: 32rpx;

  display: flex;
  justify-content: center;
  align-items: center;

  color: #290079;
  font-size: 48rpx;

  .icon {
    width: 50rpx;
    height: 50rpx;

    margin-right: 20rpx;

    background-color: #51158E;
    mask-size: 100% 100%;
  }
}
</style>